<?php
include_once '../../Config/config.php';
include_once RAIZ.'Config/conexion.php';
include_once RAIZ.'Model/Rol.php';

$titulo_page = 'Administrador de usuarios';
include_once RAIZ.'Shared/header.php';
include_once RAIZ.'Shared/Menu.php';


?>

<script>
	$(document).ready(function(){
		$("#AgregarUsuario").click(function(){			
			$.ajax({
				url:URL_PAGE+"Modulos/Usuarios/Form.php",
				data : {},
				type:"post",
				success:function(data){
					$("#window-modal").html(data);
					$("#window-modal").dialog(
						{
							autoOpen: true,
							width: 600,
							maxheight: 600,
							resizable: false,
							modal: true,
							show: 'slide',
							hide: 'slide',
							position: ["center",100],
							title: "Agregar Usuario",
							open: function (event, ui) {
								var parent = $(this);
								$('.ui-widget-overlay').click(function () {
									parent.dialog("close");
								})                        
							},

							close: function (event, ui) {                        
							}
						}
					)
				}
			});	
		});
		
		$(".eliminarUsuario").click(function(){
			var obj = $(this);
			
			$.ajax({
				url:URL_PAGE+"Modulos/Usuarios/proceso.php",
				data : {idusuario : obj.attr("data-idusuario"), action:"eliminar"},
				type:"post",
				success:function(data){
					window.location.reload();
				}
			});
		});
		
		function EditarUsuario(obj){
			//var obj = $(this);
			$.ajax({
				url:URL_PAGE+"Modulos/Usuarios/Form.php",
				data : {idusuario : obj.attr("data-idusuario")},
				type:"post",
				success:function(data){
					$("#window-modal").html(data);
					$("#window-modal").dialog(
						{
							autoOpen: true,
							width: 650,
							maxheight: 600,
							resizable: false,
							modal: true,
							show: 'slide',
							hide: 'slide',
							position: 'center',
							title: "Agregar Usuario",
							open: function (event, ui) {
								var parent = $(this);
								$('.ui-widget-overlay').click(function () {
									parent.dialog("close");
								})                        
							},
							close: function (event, ui) {                        
							}
						}
					)
				}
			});		
		}
		
		$(".editar").click(function(){
			var obj = $(this);
			EditarUsuario(obj);
		});
		
		$("#idrol , #idpais").change(function(){
			var obj = $(this);
			
			var objPais = $("#idpais");
			var objRol = $("#idrol");
						
			$.ajax({
				url:URL_PAGE+"Modulos/Usuarios/List.php",
				data : {idrol:objRol.val(), idpais:objPais.val()},
				type:"post",
				success:function(data){				
					$(".list-usuarios").html(data);
				}
			});		
		});
	
	
	})
	
</script>
<div class="container_24">
<!--	<div class="grid_5 alpha">
		<label>Nombre</label>
		<input type="text" class="text-120" name="autor">
	</div>-->
	
		
	<div class="grid_5">
			<?php
				$lista = Rol::Listar();				
			?>
			<select id="idrol" name="idrol">
				<option value="0">Seleccione Rol</option>
				<?php 
					foreach($lista as $row){
				?>
						<option value="<?php echo $row->Id;?>"><?php echo $row->Nombre;?></option>
				<?php				
					}
				?>
			</select>	
	</div>
<!--	<div class="grid_5">
			<?php
				$lista = Pais::ListarPaises();				
			?>
			<select id="idpais" name="idpais">
				<option value="0">Seleccione Pais</option>
				<?php 
					foreach($lista as $row){
				?>
						<option value="<?php echo $row->Id;?>"><?php echo Util::FormatoHtml($row->Nombre);?></option>
				<?php				
					}
				?>
			</select>	
	</div>-->	
	<div class="grid_5">
                     	<div style="float:left; width:100px; text-align:center; color:#025A8D;">
						<img src="<?php echo INI_URL?>/Content/template01/images/agregar_usuario.png"							
							title="Agregar Usuario"
							class="pointer editar"
						/>
						</div>
	</div>
</div>
<div class="list-usuarios container_24">
	<?php include_once("List.php")?>
</div>
<?php 
include_once RAIZ.'Shared/footer.php';
?>